#include "global.h"
#include <iostream>
#include "errno.h"
#include "ESPacketBase.h"
#include "manager.h"
#include "timer.h"

namespace GLOBAL{

	int back_timeout = 0;
	string backIP = "";

};


void dataInput(const int fd, const short event, void *arg){
	long long begin = getUtime();
	conn * c = (conn *)arg;
	switch(event){
		case EV_READ:
			c->input();
			break;
		case EV_WRITE:
			c->output();
			break;
		default:
			break;
	}
	long long end = getUtime();
	//if( end - begin > 10000 ){
	ERROR_LOG("dataInput process time is :%d s.|fd:%d, event:%d", (end-begin), fd, event);
	//}
}

void timeInput(const int fd, const short event, void *arg){
	ERROR_LOG("just away error|fd:%d, event:%d", fd, event);
	timer * t = (timer *)arg;
	t->timeout();
}


void vperror(const char *fmt, ...) {
    int old_errno = errno;
    char buf[1024];
    va_list ap;

    va_start(ap, fmt);
    if (vsnprintf(buf, sizeof(buf), fmt, ap) == -1) {
        buf[sizeof(buf) - 1] = '\0';
    }
    va_end(ap);

    errno = old_errno;

    perror(buf);
}


long long getUtime(){
	struct timeval tv_time;
	gettimeofday(&tv_time, NULL);
	return (tv_time.tv_sec*1000000+tv_time.tv_usec);
}







